package com.xzlf.config;

import com.alibaba.fastjson.JSON;
import com.xzlf.domain.JobTask;
import com.xzlf.service.JobTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.CronTask;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.config.TriggerTask;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Configuration
@Slf4j
public class JobTaskConfig{

    @Autowired
    private JobTaskService jobTaskService;
    public static String cron;

    @PostConstruct
    @Bean
    public Map<String, JobTask> jobTaskMap(){
        Map<String, JobTask> jobTaskMap = new HashMap<>();
        List<JobTask> list = jobTaskService.list();
        for (JobTask jobTask : list) {
            jobTaskMap.put(jobTask.getJobName(), jobTask);
        }
        return jobTaskMap;
    }




    /*@Bean
    public JobTask mailJobTask(Map<String, JobTask> jobTaskMap){
        return jobTaskMap.get("MailTask");
    }

    @Bean
    public JobTask printTask(Map<String, JobTask> jobTaskMap){
        return jobTaskMap.get("PrintTask");
    }*/
}
